﻿@using Coslen.Framework
@using MvcPaging
@model Coslen.TahorCRM.Domain.Entities.ViewModels.Searching.EventSearchViewModel

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

@using (Html.BeginForm("Index", "Event", new { page = 0 }, FormMethod.Get, new { id = "myform" }))
{
    <div class="grid-filter">
        <div class="inner">
            For : @Html.DropDownList("Period", Model.PeriodList)
            <input id="btnGo" name="btnGo" type="submit" value="Apply Filter" />
        </div>
    </div>

    <div class="grid-header">
        <div class="grid-results">
            <div class="inner">
                <span style="float: left">
                    @string.Format("{0} records found. Page {1} of {2}", Model.SearchResults.TotalItemCount, Model.SearchResults.PageNumber, Model.SearchResults.PageCount)
                </span>
                <span style="float: right">Show @Html.DropDownList("PageSize", Model.PageSizeList, new { onchange = "document.getElementById('myform').submit()" })
                    results per page 
                </span>
                <div style="clear: both">
                </div>
            </div>
        </div>
        <div class="paging">
            <div class="pager">
                @Html.Pager(Model.SearchResults.PageSize, Model.SearchResults.PageNumber, Model.SearchResults.TotalItemCount, new { Period = Model.Period, PageSize = Model.PageSize })
            </div>
        </div>
    </div>

}

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="GenericTable fullWidth">
    <tr class="GenericTable-HeaderRow">
        <th>
            Name
        </th>
        <th>Short Description</th>
        <th>
            Starting At
        </th>
        <th>
            Ending At
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model.SearchResults.Select((x, i) => new { Data = x, Index = i }))
    {
        <tr class="@( item.Index % 2 == 0 ? "GenericTable-RowAlt" : "GenericTable-Row")">
            <td>
                @Html.DisplayFor(modelItem => item.Data.EventType.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.ShortDescription)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.StartingAt)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.EndingAt)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.Data.EventId }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Data.EventId })
            </td>
        </tr>
    }

</table>


<div class="grid-header">
    <div class="paging">
        <div class="pager">
            @Html.Pager(Model.SearchResults.PageSize, Model.SearchResults.PageNumber, Model.SearchResults.TotalItemCount, new { Period = Model.Period, PageSize = Model.PageSize })
        </div>
    </div>
</div>
